using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

/// <summary>
/// 生成一张黑白相间的纹理
/// </summary>
public class GenSquare : MonoBehaviour
{
    public int width = 256;
    public int height = 256;
    public int gridSize = 8;

    void Start()
    {
        Gen();
    }

    public void Gen()
    {
        Texture2D texture2D = new Texture2D(width, height);
        for (int x = 0; x < width; x++)
        {
            for (int y = 0; y < height; y++)
            {
                int x1 = width / gridSize;
                int y1 = height / gridSize;

                if ((x / x1 + y / y1) % 2 == 0)
                    texture2D.SetPixel(x, y, Color.white);
                else
                    texture2D.SetPixel(x, y, Color.black);
            }
        }
        texture2D.Apply();
        GetComponent<RawImage>().material.mainTexture = texture2D;
    }
}